package com.meyoung.day2;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import static java.lang.Thread.*;

public class SelectTest {
    WebDriver driver;
    @BeforeMethod
    public void openchromeTest01(){
        //设置chromedriver路径
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\cll520\\IdeaProjects\\selenium11\\drivers\\chromedriver.exe");
        //实例化Chromedriver
        driver = new ChromeDriver();
    }
    /*
    打开我们的测试页面
    下拉框选择vivo
    第二次选择huawei
    第三次选择iphone
     */
    @Test
    public void selectTest() throws InterruptedException {
        driver.get("file:///C:/Users/cll520/Desktop/index.html");
        WebElement selectEl = driver.findElement(By.id("moreSelect"));
        //实例化Select类
        Select select = new Select(selectEl);
        //通过索引选择下拉框
        select.selectByIndex(2);
        Thread.sleep(2000);
        //通过属性value值选择下拉框
        select.selectByValue("iphone");
        Thread.sleep(2000);
        //通过文本值选择下拉框
        select.selectByVisibleText("huawei");
        Thread.sleep(2000);
    }
    @AfterMethod
    public void closedBrowser(){
        driver.quit();
    }
}
